package com.xxgc.cloud.consumer.springcloudconsumer.aop;

import com.xxgc.cloud.api.result.Result;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 通过aop注入 版本号和当前系统环境
 */
@Component
@Aspect
public class ResultControllerAOP {

    @Autowired
    private SystemInfo si;

    //抽取切点表达式
    @Pointcut("execution(* com.xxgc.cloud.consumer.springcloudconsumer.controller.*.*(..))")
    public void resultPoint(){}

    @AfterReturning(value = "ResultControllerAOP.resultPoint()",returning = "obj")
    public Object afterReturning(JoinPoint joinPoint,Object obj){
        //强制类型转换
        Result result = (Result) obj;
        result.setVersion(si.getVersion());
        result.setEnvironment(si.getEnvironment());
        return obj;
    }
}
